<?php
date_default_timezone_set('America/Argentina/Buenos_Aires');
 $dias = array('Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes');
 $horas = array('06', '07', '08', '09', '10', '11',
                 '12', '13', '14', '15', '16', '17', 
                 '18', '19', '20', '21', '22');
?>

    <script type='text/javascript'>
       $(document).ready(function() { 
           $('#formulario').validate({
            rules:{
                'horariosCheckbox[]':{
                    required:true
                }
            },
            messages: {
               'horariosCheckbox[]':{
                   required: function(){
                        $('#msg').html('<div class="alert alert-error">\n\
                                            <button type="button" class="close" data-dismiss="alert">&times;</button>\n\
                                                <p class="text-error">ERROR! Se nececita por lo menos asignar una clase... <i class="icon-hand-up" /></p>\n\
                                        </div>');
                        return false;
                   }
               }
            },
            submitHandler: function(form){
                form.submit();
            },
            invalidHandler: function(){}
            });
       });
    </script>
    
    <div class="alert alert-info">
            <i class="icon-info-sign icon-large"></i>  <strong>Atención!</strong>, los días de actividades se asignarán a: <code><?php echo $alumno;?></code>.
    </div> 
   
   <?php if ($view['session']->hasFlash('notice')): ?>
        <div class="flash-notice">
            <?php echo $view['session']->getFlash('notice') ?>
        </div>
    <?php endif; ?>

    <form id="formulario" name="formulario" action="<?php echo $view['router']->generate('admin_clase_alumno_save', array('id' => $idAlumno)) ?>" 
          method="post" class='form-horizontal form-bordered form-validate'>                     
        <table id="table" class="table dataTable table-fixed-medium">
            <thead><tr>
                <th>Horarios</th>   
                <?php foreach ($dias as $dia) {?>
                    <th style="text-align: center;"><?php echo $dia;?></th>                                                                                           
                <?php
                }?>
            </tr></thead>
            <tbody>
                <?php for ($index1 = 0; $index1 < count($horas); $index1++) {?>
                <tr style="">
                    <th><?php echo $horas[$index1].":00";?></th>
                    
                    <?php for ($index2 = (5*$index1); $index2 < (5*$index1+5); $index2++) {?>
                        
                            <?php 
                                if($Clases[$index2]->getHabilitado()){  
                                    if($Clases[$index2]->getNroCama() == 0){?> 
                                        <td class="alert-error error" style="text-align: center;" title="<?php echo $Clases[$index2]->getNroCama();?> - lugares libres">
                                            <strong>
                                                <?php echo $Clases[$index2]->getNroCama();?>
                                                <img src="<?php echo $view['assets']->getUrl('bootstrap/img/gym/joggingError.png'); ?>" alt="" />
                                            </strong>
                                            <input  type="checkbox" 
                                                    value="<?php echo $Clases[$index2]->getCodigoClase();?>" 
                                                    name="horariosCheckbox[]"
                                                    style="margin-bottom: 5px; margin-left: 5px;"
                                                    disabled="true"
                                            >
                                        </td>
                                <?php
                                    } else {
                                        $alumnoTieneEsteDia = false;
                                        foreach ($alumno->getClases() as $clase) {
                                            if($clase->getId() == $Clases[$index2]->getId()){
                                                $alumnoTieneEsteDia = true;
                                            }
                                        }
                                        if(!$alumnoTieneEsteDia){
                                            if($Clases[$index2]->getNroCama() == 1){?>
                                                <td style="background-color: #fcf8e3;">
                                                <strong style="color: #c09853;">
                                            <?php
                                            } else {?>
                                                <td class="alert-success success" style="text-align: center;" title="<?php echo $Clases[$index2]->getNroCama();?> - lugares libres">
                                                <strong>
                                            <?php
                                            }?>
                                                    <?php echo $Clases[$index2]->getNroCama();?>
                                                    <img src="<?php echo $view['assets']->getUrl('bootstrap/img/gym/joggingSuccess.png'); ?>" alt="" />
                                                </strong>
                                                <input  type="checkbox" 
                                                        value="<?php echo $Clases[$index2]->getCodigoClase();?>" 
                                                        name="horariosCheckbox[]"
                                                        style="margin-bottom: 5px; margin-left: 5px;"
                                                >
                                             </td>
                                    <?php
                                        } else {?>
                                             <td class="alert-info info" style="text-align: center;" title="<?php echo $alumno; ?>">
                                                 <strong><img src="<?php echo $view['assets']->getUrl('bootstrap/img/gym/yogaMio.png'); ?>" alt="" /></strong>
                                                 <input  type="checkbox" 
                                                    value="<?php echo $Clases[$index2]->getCodigoClase();?>" 
                                                    name="horariosCheckbox[]"
                                                    style="margin-bottom: 5px; margin-left: 5px;"
                                                    disabled="true"
                                                    >
                                            </td>
                                        <?php
                                        }
                                    };
                                }  else { ?>
                                    <td style="text-align: center;">
                                        <span class="badge">-</span>
                                    </td>
                            <?php
                                };
                    }?>
                </tr>                      
                <?php
                }?>
            </tbody>
        </table>
        <div id="msg"></div>
        <div class="form-actions offset1">
            <input type="submit" class="button button-basic-blue" value="Aceptar">
            <button type="button" class="button button-basic">Cancelar</button>
        </div>
    </form>
